import React, {Component} from 'react';
import axios from "axios";

class Search extends Component {
    search = () => {
        //获取输入(连续结构赋值+重命名)
        let {keyword: {value: val}} = this;
        this.props.updateAppState({isFirst: false, isLoading: true})//发送请求前通知App更新状态
        //发送网络请求
        axios.get(`https://api.github.com/search/users?q=${val}`).then(
            value => {
                this.props.updateAppState({isLoading: false, users: value.data.items})
            },
            error => {
                this.props.updateAppState({isLoading: false, err: error.message})
            }
        )
    }

    render() {
        return (
            <section className="jumbotron">
                <h3 className="jumbotron-heading">搜索用户</h3>
                <div>
                    <input ref={c => this.keyword = c} type="text" placeholder="输入关键词搜索"/>&nbsp;
                    <button onClick={this.search}>搜索用户</button>
                </div>
            </section>
        );
    }
}

export default Search;